﻿CREATE PROCEDURE [dbo].[AddUser]
@UserName NVARCHAR (50), @FullName VARCHAR (50), @UserTypeID INT, @RoleID INT, @ExpectedHours SMALLINT, @IsActive BIT, @StartDate DATETIME, @IsAdministrative BIT, @PTOHoursRolledIntoCurrentYear DECIMAL (6, 2)
AS
IF Not Exists (SELECT UserName FROM Users WHERE UserName=@UserName)
  BEGIN

	INSERT INTO Users
	(
		Username,  
		FullName,
		UserTypeID,
		RoleID,
		ExpectedHours,
		IsActive,
		StartDate,
		IsAdministrative,
		PTOHoursRolledIntoCurrentYear
	)
	VALUES
	(   
		@UserName, 
		CASE WHEN @FullName = '' THEN Null ELSE @FullName END,
		@UserTypeID,
		@RoleID,
		@ExpectedHours,
		@IsActive,
		@StartDate,
		@IsAdministrative,
		@PTOHoursRolledIntoCurrentYear
	)
	
	SELECT
	    @@Identity AS UserID    
  END
ELSE
	SELECT -2 AS UserID

